package lambda_expression.jdk;

import java.util.Arrays;
import java.util.List;
import java.util.StringJoiner;
import java.util.stream.Collectors;

public class StringJoinerTest {
    public static void main(String[] args) {
        String s = extracted();
        System.out.println(s);
        String s2 = extracted2();
        System.out.println(s2);
    }

    private static String extracted2() {
        List<Integer> numbers = Arrays.asList(1, 2, 3, 4);
        String commaSeparatedNumbers = numbers.stream()
                .map(i -> i.toString())
                .collect(Collectors.joining("| "));

        return commaSeparatedNumbers;
    }

    private static String extracted() {
        StringJoiner sj = new StringJoiner(":", "[", "]");
        sj.add("George").add("Sally").add("Fred");
        String desiredString = sj.toString();
        return desiredString;
    }
}
